package com.mew.slots.core.game.sgj.service;


import com.mew.common.enm.SlotsWinType;
import com.mew.common.entity.game.WinFree;
import com.mew.slots.core.common.game.BaseGameService;
import com.mew.slots.core.common.game.vo.BasePlayMsgs;
import com.mew.slots.core.common.messge.response.SlotsPlayResponseMessage;
import com.mew.slots.core.common.vo.StrategyGameVO;
import com.mew.slots.core.game.sgj.message.SgjBounsPlayResponseMessage;
import com.mew.slots.core.game.sgj.message.SgjPlayResponseMessage;
import com.mew.slots.core.game.sgj.roller.SgjIli;
import com.mew.slots.core.game.sgj.room.SgjRoom;
import com.mew.slots.core.game.sgj.room.bouns.FruitMaryGame;

public class SgjService extends BaseGameService {
    @Override
    public BasePlayMsgs startGame(StrategyGameVO player) {
        int jackpotControlType=player.getControlType();
        SgjRoom room = new SgjRoom();
        room.init(player.getRollerId(), SgjIli.getInstance(),null,player.getWinType()==SlotsWinType.Free.code(),player.getInBetNumber(),jackpotControlType);
        room.roundPlayIli();
        return room.getRes();
    }

    @Override
    public SlotsPlayResponseMessage myResp(WinFree winFree, BasePlayMsgs res) {
        SgjPlayResponseMessage message = new SgjPlayResponseMessage();
        message.setBouns(res.getBouns());
        winFree.setBounsRate(res.getBouns());
        winFree.setBounsNumber(0);
        return message;
    }

    public SgjBounsPlayResponseMessage bouns(StrategyGameVO gameVO){
        SgjBounsPlayResponseMessage message = new SgjBounsPlayResponseMessage();
        //获取winFree
        WinFree winFree = gameVO.getWinFree();

        Integer bounsRate = winFree.getBounsRate();//剩几次炸弹机会
        bounsRate--;
        //给前端剩余次数
        message.setBounsTimes(bounsRate);
        if (bounsRate<0){
            return message;
        }

        Integer bounsNumber = winFree.getBounsNumber();//第几次
        Integer bounsType = winFree.getBounsType();//第几次
        Long bet = winFree.getBet();//第几次
        message = FruitMaryGame.roundMary(bounsNumber, bounsType, bet);

        //中炸弹减次数
        if (message.icon==-1){
            winFree.setBounsRate(bounsRate);
        }

        //游戏次数增加
        if (winFree.getBounsRate()<1){
            winFree.setBounsNumber(0);
        }else {
            winFree.setBounsNumber(bounsNumber+1);
        }

        //处理
        gameVO.setWinType(SlotsWinType.Special.code());
        gameVO.setPaymentNumber(message.getWinGold());
        gameVO.setBetTimes(message.getMult());
        gameVO.iconResult(message.getCenter(),message.icon);

        return message;
    }
    @Override
    public void myAfterResp(SlotsPlayResponseMessage message,StrategyGameVO player, BasePlayMsgs res) {}

}
